package fragment;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.swim.MainActivity2;
import com.example.swim.R;

import java.util.List;

public class tou_tiao_Adaptet extends RecyclerView.Adapter<tou_tiao_Adaptet.adaptet> {
    private List<tou_tiao_api.ResultDTO.DataDTO> list;
    private Context context;

    public tou_tiao_Adaptet(List<tou_tiao_api.ResultDTO.DataDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }
    @NonNull
    @Override
    public adaptet onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.main,null);
        return new adaptet(view);
    }
    @Override
    public void onBindViewHolder(@NonNull adaptet holder, int position) {
        tou_tiao_api.ResultDTO.DataDTO api=list.get(position);
        holder.te_titl.setText(""+api.getTitle());
        Glide.with(context).load(api.thumbnail_pic_s).into(holder.img);
        holder.te_titl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, MainActivity2.class);
                String url=api.getUrl();
                intent.putExtra("url=",url);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class adaptet extends RecyclerView.ViewHolder {
        private TextView te_titl,te_neiron;
        private ImageView img;
        public adaptet(@NonNull View itemView) {
            super(itemView);
            img=itemView.findViewById(R.id.img);
            te_titl=itemView.findViewById(R.id.te_titl);
        }
    }
}
